package com.muatocroi.tornado;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.text.InputType;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.ToggleButton;

public class SlideShowActivity extends ActivityMCAbstractClass implements OnClickListener{
	ToggleButton tgBtnLazer, tgBtnZoom;
	SignalSender sender;
	View vTouchPad;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_slide_show);
		setContentView(R.layout.action_slide_show2);
		sender = SignalSender.getSender();
		if (!sender.isSending())
		{
			sender.BeginSend();
		}
		vTouchPad = (View)findViewById(R.id.touchPadSlide);
		
		ProcessSlideShowControl2.setSender(sender);
		ProcessSlideShowControl2.setTouchView(vTouchPad);
		
		tgBtnLazer = (ToggleButton)findViewById(R.id.tgBtnLazer);
		tgBtnLazer.setOnClickListener(this);
		
		tgBtnZoom = (ToggleButton)findViewById(R.id.tgBtnZoom);
		tgBtnZoom.setOnClickListener(this);
		
		Button btnBlack = (Button)findViewById(R.id.btnBlack);
		btnBlack.setOnClickListener(this);

		Button btnGoToSlide = (Button)findViewById(R.id.btnGoToSlide);
		btnGoToSlide.setOnClickListener(this);
		
		Button btnShowAllSlide = (Button)findViewById(R.id.btnShowAllSlide);
		btnShowAllSlide.setOnClickListener(this);
	}
	private void changeTouchHandle(boolean isMouse)
	{
		if (isMouse)
		{
			ProcessTouchPad.setSender(sender);
			ProcessTouchPad.setTouchView(vTouchPad);
		}
		else
		{
			ProcessSlideShowControl2.setSender(sender);
			ProcessSlideShowControl2.setTouchView(vTouchPad);
		}
	}
	@Override
	public void onClick(View arg0) {
		int id = arg0.getId();
		switch(id){
		case R.id.tgBtnLazer:
			
			sender.Send(CommandPowerpoint.Lazer(tgBtnLazer.isChecked()));
			changeTouchHandle(tgBtnLazer.isChecked());
			break;
		case R.id.tgBtnZoom: 
			if (tgBtnZoom.isChecked())
			{
				sender.Send(CommandScreen.ZoomIn());
			}
			else
			{
				sender.Send(CommandScreen.ZoomExit());
			}
			changeTouchHandle(tgBtnZoom.isChecked());
			break;
		case R.id.btnBlack:
			sender.Send(CommandPowerpoint.BlackScreen());
			break;
		case R.id.btnShowAllSlide:
			sender.Send(CommandPowerpoint.ShowAllSlide());
			break;
		case R.id.btnGoToSlide:
			AlertDialog.Builder alert = new AlertDialog.Builder(this);
			alert.setTitle("Slide number");
			final EditText input = new EditText(this);
			input.setInputType(InputType.TYPE_CLASS_NUMBER);
			alert.setView(input);
			
			alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
				  String value = input.getText().toString();
				  sender.Send(CommandPowerpoint.GoToSlide(Integer.parseInt(value)));
				  }
				});

				alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
				  public void onClick(DialogInterface dialog, int whichButton) {
				    
				  }
				});

				alert.show();
			break;
		}
	}

}
